/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.amuthu.expression.function.indicator;

import org.amuthu.DataStore;
import org.amuthu.expression.Expression;
import org.amuthu.indicator.SAR;
import org.amuthu.parser.ExpressionVisitor;

/**
 *
 * @author prabhu
 */
public class SarFunction extends BaseIndicatorFunction
{
   private double acceleration;
   private double maximum;

   public SarFunction()
   {
   }

   @Override
   public boolean doUpdateParameters(DataStore dataStore, Expression[] arguments, ExpressionVisitor visitor)
   {
      if (arguments.length < 2)
      {
         return false;
      }

      acceleration = visitor.evaluate(arguments[0]);
      maximum = visitor.evaluate(arguments[1]);

      int startOffset = (arguments.length > 2) ? (int) visitor.evaluate(arguments[2]) : 0;

      setOffset(startOffset);

      return true;
   }

   @Override
   public double calculateIndicator(DataStore dataStore, Expression[] arguments, ExpressionVisitor visitor)
   {
      SAR sar = new SAR(dataStore, acceleration, maximum, getOffset());

      return sar.calculate();
   }

   @Override
   public int calculateDependency(DataStore dataStore, Expression[] arguments, ExpressionVisitor visitor)
   {
      SAR sar = new SAR(dataStore, acceleration, maximum, getOffset());

      return sar.getDayDependency();
   }
}
